<template>
	<view>
		<navNav :navobj="navobj"></navNav>
		<view class="exchangeBox">
			<view class="inputBox">
				<view class="input">
					<uni-easyinput placeholder="请输入兑换码"></uni-easyinput>
				</view>
				<view class="button">兑换</view>
			</view>
			<view class="tips">仅支持维修超人优惠卷兑换</view>
		</view>
		<view class="tabBar">
			<!-- 待领取、未使用（（能不能使用）是否过期状态）、已使用 -->
			<view :class="actIndex==='expired'?'actTab':''" @click="choose('expired')" class="tab">待领取</view>
			<view :class="actIndex==='unused'?'actTab':''" @click="choose('unused')" class="tab">未使用</view>
			<view :class="actIndex==='used'?'actTab':''" @click="choose('used')" class="tab">已使用</view>
			
		</view>
		<view class="listBox">
			<view class="item" @click="chooseBack(item)" v-for="(item,index) in list" :key="index">
				<view class="left">
					<view class="priceBox">
						<view class="value">{{item.coupon.discountType}}</view>
						<view class="rule">{{item.coupon.usedCondition}}</view>
					</view>
					<view class="form">
						<view class="name">{{item.coupon.name}}</view>
						<view class="time">{{item.updateTime}}</view>
					</view>
				</view>
				<view class="right">{{item.status.name}}</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {reactive,ref,getCurrentInstance,onMounted} from 'vue'
	import {onLoad} from "@dcloudio/uni-app"
	const {proxy} = getCurrentInstance()
	const navobj = reactive({
				title:'优惠卷',
				image:true
	})
	const actIndex=ref('expired') 
	const tags=ref(['服务类目不合理', '体验问题', '其它', '功能异常', '新功能建议', '搜索服务/建议']) 
	const list=ref([]) 
	const allData=ref({})
	const type=ref('')
	const total=ref('')
	onLoad((e)=>{
		type.value = e.type
		total.value = e.total
		getData()
	}) 

	const chooseBack=(item)=>{
		if(this.type == 'choose'){
			uni.$emit('coupon',item)
			uni.navigateBack()
		}
	}
	const getData=async(item)=>{
		const result = await proxy.$api.coupon()
		if(result.code==200){
			allData.value = res.data
			list.value = allData.value[actIndex.value]
		}
	}
	const choose=(name)=>{
		actIndex.value = name
		list.value = allData.value[name]
	}


</script>

<style lang="scss">
	page {
		background-color: $MainBackColor;
	}
</style>

<style lang="scss" scoped>
	.listBox{
		padding: 20px;
		.item{
			display: flex;
			justify-content: space-between;
			margin-bottom: 10px;
			.left{
				display: flex;
				align-items: center;
				background-color: white;
				border-radius: 10px;
				padding: 20px;
				flex: auto;
				.priceBox{
					display: flex;
					flex-direction: column;
					align-items: center;
					.value{
						font-size: 22px;
						font-weight: bold;
						color: $red;
					}
					.rule{
						font-size: 14px;
						color: $red;
					}
				}
				.form{
					margin-left: 10px;
					.name{
						font-weight: bold;
						font-size: 15px;
					}
					.time{
						font-size: 12px;
						color: $grey;
					}
				}
			}
			.right{
				background-color: white;
				border-radius: 10px;
				padding: 10px;
				writing-mode: vertical-lr;
				text-align: center;
				color: $grey;
				margin-left: 1px;
			}
		}
	}
	
	.exchangeBox {
		background-color: white;
		padding: 10px 20px;

		.inputBox {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.input {
				flex: auto;
			}
			.button{
				background-color: $blue;
				color: white;
				padding: 8px 15px;
				margin-left: 10px;
				border-radius: 5px;
			}
		}
		
		.tips{
			color: $grey;
			font-size: 14px;
			margin-top: 5px;
		}
	}


	.feedbackBox {
		padding: 20px;
		background-color: white;
		margin: 10px 0px;

		.imgs {
			display: flex;
			align-items: center;
			margin-top: 10px;

			.img {
				height: 50px;
				width: 50px;
			}
		}

		.content {
			padding: 10px 0;
		}

		.tagsBox {
			display: flex;
			flex-wrap: wrap;
			border-bottom: 1px solid $shollowGrey;
			padding-bottom: 10px;

			.tag {
				padding: 3px 5px;
				font-size: 14px;
				border: 1px solid rgba(0, 0, 0, 0.1608);
				border-radius: 5px;
				margin-top: 10px;
				margin-right: 10px;
			}
		}
	}

	.tabBar {
		display: flex;
		align-items: center;
		background-color: white;
		padding: 0px 20px;

		.tab {
			padding: 10px 0px;
			width: 50%;
			font-weight: bold;
			box-sizing: border-box;
			text-align: center;
		}

		.actTab {
			color: $blue;
			border-bottom: 2px solid $blue;
		}
	}

	.buttonBox {
		position: fixed;
		bottom: 0px;
		left: 0px;
		background-color: $blue;
		color: white;
		padding: 10px;
		width: calc(100vw - 60px);
		margin: 20px;
		text-align: center;
		border-radius: 20px;
	}
</style>